import { useEffect } from 'react'
import { useLocation } from 'react-router-dom'

export default function useScrollTop() {
  const location = useLocation()

  // location.pathname 监听当前路由路径是否发生了改变
  useEffect(() => {
    // 滚动到页面顶部
    window.scrollTo({
      top: 0,
      left: 0,
      behavior: 'smooth',
    })
  }, [location.pathname])
}
